package com.newtouch.bxzs.database.service.impl;

import com.newtouch.bxzs.common.base.BaseException;
import com.newtouch.bxzs.database.service.CheckVerCodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * 校验验证码service实现类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020年12月29日</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 * 
 * @author Amour
 * 
 * @version 1.0.0
 * @since 1.0.0
 */
@Service
public class CheckVerCodeServiceImpl implements CheckVerCodeService {

	/** 静态变量：系统日志 */
	private static final Log logger = LogFactory.getLog(CheckVerCodeServiceImpl.class);

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.newtouch.bxzs.database.service.CheckVerCodeService#checkVerCode(java.
	 * util.Map, java.lang.String, java.lang.String)
	 */
	@Override
	public Boolean checkVerCode(Map<String, String> verCodeMap, String operationId, String verCode) {
		// TODO 后期修改为从REDIS获取
		String code = verCodeMap.get(operationId);
		if (StringUtils.isEmpty(code)) {
			logger.info("验证码已失效");
			throw new BaseException("-1","验证码已失效，请重新获取！");
		}
		Boolean check = code.equals(verCode);
		if (!check) {
			logger.info("验证码输入错误！");
			throw new BaseException("-1","验证码输入错误！");
		}
		return check;
	}
}
